﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace TestUDPPacket
{
    class Program
    {
        public static string ByteArrayToString(byte[] ba)
        {
            StringBuilder hex = new StringBuilder(ba.Length * 2);
            foreach (byte b in ba)
                hex.AppendFormat("{0:x2}", b);
            return hex.ToString();
        }

        public static void  Xuat()
        {
            int i=0;
            do
            {
                
                Console.WriteLine(i);
                i++;
                Thread.Sleep(20);
            } while (i<1000);
        }

        static void Main(string[] args)
        {
            
                Thread th = new Thread(new ThreadStart(Xuat));
                th.Start();
          

            Thread th1 = new Thread(new ThreadStart(Xuat));
            th1.Start();
            //byte[] byteSend = new byte[1024];
            //Byte[] receiBytes = { 0x76, 0x5f, 0x76, 0x5f, 0x00, 0x48, 0x00, 0x00 };


            //byte[] vals = { 0x01, 0xAA, 0xB1, 0xDC, 0x10, 0xDD };

            //string str = BitConverter.ToString(vals);
            //Console.WriteLine(str);

            //str = BitConverter.ToString(vals).Replace("-", "");
            //Console.WriteLine(str);

            ///*Output:
            //  01-AA-B1-DC-10-DD
            //  01AAB1DC10DD
            // * 
            // * 
            //*/
            //string s = ByteArrayToString(receiBytes);
            //Console.WriteLine(s);


            //string hexValues = "765f 765f 0048 0000";
            //string[] hexValuesSplit = hexValues.Split(' ');
            //foreach (String hex in hexValuesSplit)
            //{
            //    // Convert the number expressed in base-16 to an integer. 
            //    int value = Convert.ToInt32(hex, 16);

            //    // Get the character corresponding to the integral value. 
            //    string stringValue = Char.ConvertFromUtf32(value);
            //    char charValue = (char)value;
            //    Console.WriteLine("hexadecimal value = {0}, int value = {1}, char value = {2} or {3}",
            //                        hex, value, stringValue, charValue);
            //}
            //byte[] arrSrc = { receiBytes[0], receiBytes[1] };
            //string srcPort = BitConverter.ToString(arrSrc);
            //srcPort = BitConverter.ToString(arrSrc).Replace("-", "");
            //int srcPortInt = Convert.ToInt32(srcPort, 16);
            //Console.WriteLine("src port int " + srcPortInt.ToString());

            //byte[] arrDes = { receiBytes[2], receiBytes[3] };
            //string desPort = BitConverter.ToString(arrDes);
            //desPort = BitConverter.ToString(arrDes).Replace("-", "");
            //int desPortInt = Convert.ToInt32(desPort, 16);
            //Console.WriteLine("des port int " + desPortInt.ToString());

            //byte[] arrLength = { receiBytes[4], receiBytes[5] };
            //string lengthstr = BitConverter.ToString(arrLength);
            //lengthstr = BitConverter.ToString(arrLength).Replace("-", "");
            //int length = Convert.ToInt32(lengthstr, 16);
            //Console.WriteLine("length int " + length.ToString());

            //byte[] arrCheckSum = { receiBytes[6], receiBytes[7] };

            //string checkSum = BitConverter.ToString(arrCheckSum);
            //checkSum = BitConverter.ToString(arrCheckSum).Replace("-", "");
            //int checkSumint = Convert.ToInt32(checkSum, 16);
            //Console.WriteLine("checksum int " + checkSumint.ToString());

            //string data = "";
            //int lengthData = length - 8;
            //if (lengthData > 0)
            //{
            //    byte[] arrData = new byte[lengthData];


            //    for (int i = 0; i < lengthData; i++)
            //    {
            //        arrData[i] = receiBytes[8 + i];
            //    }




            //    byte[] macAdd = new byte[6];
            //    for (int i = 0; i < 6; i++)
            //    {
            //        macAdd[i] = arrData[i];
            //    }

            //    byte[] temp = new byte[arrData.Length - 6];


            //    for (int i = 0; i < arrData.Length - 6; i++)
            //    {
            //        temp[i] = arrData[i + 6];
            //    }

            //    data = Encoding.Default.GetString(temp);

            //}
        }

    }
}